<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div class="hezuoshang">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="合作商搜索：">
        <el-input v-model.trim="formInline.name" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="hzsSearch"
          >搜索</el-button>
          <el-button type="success" icon="el-icon-search" @click="hzsReset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="dw-bottom">
      <div class="dw-add">
        <el-button
          type="primary"
          icon="el-icon-circle-plus-outline"
          @click.native="addHzs"
          >新建</el-button
        >
      </div>
      <!-- 列表区域 -->
      <div class="dw-content">
        <el-table :data="hzsList" style="width: 100%">
          <el-table-column prop="num" label="序号" width="80" type="index">
          </el-table-column>
          <el-table-column prop="name" label="合作商名称" width="135">

          </el-table-column>
          <el-table-column prop="account" label="账号" width="135">
          </el-table-column>
          <el-table-column prop="vmCount" label="设备数量" width="100">
          </el-table-column>
          <el-table-column prop="ratio" label="分成比例" width="100">
            <template slot-scope="scope">
              {{scope.row.ratio}}%
            </template>
          </el-table-column>
          <el-table-column prop="contact" label="联系人" width="130">
          </el-table-column>
          <el-table-column prop="mobile" label="联系电话" width="150">
          </el-table-column>
          <el-table-column prop="labor" label="操作" class="caozuo">
            <template v-slot={row}>
              <span @click="czmmHzs(row.id)">重置密码</span>
              <span @click="hzsXq(row)">查看详情</span>
              <span @click="hzsEdit(row)">修改</span>
              <span @click="delHzs(row.id)">删除</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="dw-footer">
          <!-- 页码 -->
          <Page
            :total="Number(totalCount)"
            :totalPage="Number(totalPage)"
            :page.sync="data.pageIndex"
            @gengxin='hzs'
          ></Page>
        </div>
      </div>
      <!-- 新增 -->
      <HzsXz :hzsVisible.sync='hzsVisible' @gengxin='hzs' ref='xz'></HzsXz>
      <!-- 详情 -->
      <hzsXq :hzsXqVisible.sync='hzsXqVisible' ref="hzsXq"></hzsXq>
    </div>
    <!-- 重置密码确认框 -->
    <el-dialog
  title=""
  :visible="hzsShow"
  width="25%"
  center
  @close="closeFn"
  class="hzsDialog">
  <template #title>
    <i class="el-icon-warning" style="color:#ff665f"></i>
    <span>确定要重置合作商密码吗？</span>
    </template>
  <!-- <span>需要注意的是内容是默认不居中的</span> -->
  <span slot="footer" class="dialog-footer">
    <el-button @click="closeFn">取 消</el-button>
    <el-button type="primary" @click="czmmHzsFn">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import hzsXq from './components/hzsXq.vue'
import Page from './components/Page.vue'
import HzsXz from './components/HzsXz.vue'
import { getHzs, delHzs, czmmHzs } from '@/api/dianweiguanli/hezuoshang'
export default {
  components: {
    Page,
    HzsXz,
    hzsXq
  },
  data () {
    return {
      hzsXqVisible: false,
      hzsShow: false,
      hzsVisible: false,
      formInline: {
        name: ''
      },
      hzsList: [],
      data: {
        pageIndex: 1,
        pageSize: 10
      },
      totalCount: 0, // 总量
      totalPage: 0, // 总页数
      id: ''
    }
  },
  created () {
    this.hzs()
  },
  mounted () {},
  methods: {
    // 页面渲染
    async hzs () {
      const res = await getHzs(this.data)
      this.hzsList = res.data.currentPageRecords
      // this.hzsList.forEach((item) => {
      //   item.ratio = item.ratio + '%'
      // })
      this.totalCount = res.data.totalCount
      this.totalPage = res.data.totalPage
    },
    // 搜索合作商
    async hzsSearch () {
      const obj = { ...this.data, ...this.formInline }
      const res = await getHzs(obj)
      this.hzsList = res.data.currentPageRecords
      // this.hzsList.forEach((item) => {
      //   item.ratio = item.ratio + '%'
      // })
    },
    // 重置合作商
    hzsReset () {
      this.hzs()
      this.formInline = {
        name: ''
      }
    },
    // 新增
    addHzs () {
      this.hzsVisible = true
    },
    // 删除
    async delHzs (id) {
      try {
        await this.$confirm('确定删除吗？')
        await delHzs(id)
        this.hzs()
        this.$message.success('删除成功')
      } catch (err) {
        console.log(err)
        this.$message.error(err.response.data)
      }
    },
    // 重置密码
    czmmHzs (id) {
      this.hzsShow = true
      this.id = id
    },
    // 关闭重置密码确认框
    closeFn () {
      this.hzsShow = false
    },
    // 重置密码弹出框确定
    async czmmHzsFn () {
      await czmmHzs(this.id)
      this.$message.success('密码重置成功')
      this.closeFn()
    },
    // 详情
    hzsXq (row) {
      this.hzsXqVisible = true
      console.log(row)
      // console.log(this.$refs.hzsXq)
      this.$refs.hzsXq.obj = row
    },
    // 修改
    hzsEdit (row) {
      console.log(row)
      // row.ratio = row.ratio.replace('%', '')
      this.$refs.xz.hzsForm = row
      this.hzsVisible = true
    }
  }
}
</script>
<style lang="less" scoped>
.hezuoshang {
  * {
    box-sizing: border-box;
  }
  padding: 80px 20px 20px;
  background-color: #f8fafd;

  .dw-bottom {
    padding-left: 17px;
    padding-top: 20px;
    width: 1185px;
    height: 673px;
    background-color: #fff;
    .dw-add {
      margin-bottom: 20px;
      width: 1153px;
      height: 36px;
      .el-button--primary {
        // display: inline-block;
        cursor: pointer;
        width: 80px;
        height: 36px;
        color: #fff;
        font-size: 14px;
        background-color: #ff6726;
        border-color: #ff6726;
        padding: 0;
      }
    }
    .dw-content {
      /deep/.el-table th {
        background-color: #f3f6fb;
      }
      span {
        margin-right: 10px;
        cursor: pointer;
        font-size: 14px;
        color: #5f84ff;
      }
      span:last-child {
        color: #ff5a5a;
      }
      .dw-footer {
        display: flex;
        justify-content: space-between;
        padding: 32px 16px;
        width: 1153px;
        height: 96px;
        p {
          font-size: 16px;
          color: #606266;
        }
        .btn {
          .btn1,
          .btn2 {
            // display: flex;
            background-color: #d5ddf8;
            width: 70px;
            height: 32px;
            margin: 0 16px;
            padding: 0;
          }
        }
      }
    }
  }
  /deep/.el-dialog {
    position: relative;
    margin: 0 auto 50px;
    background: #fff;
    border-radius: 12px;
    // -webkit-box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
    // box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
    // -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 50%;
    .el-dialog__title {
      font-size: 18px;
      font-weight: 900;
      color: #333;
    }
    .el-dialog__body {
      padding: 20px 20px 0;
    }
    .el-form-item {
      display: flex;
      align-items: center;

      .el-form-item__content {
        margin-left: 0 !important;
      }

      .el-form-item__label {
        margin-left: 20px;
      }
      .el-input__inner {
        width: 396px;
        height: 36px;
      }
      .el-textarea__inner {
        width: 396px;
        height: 82px;
      }
    }
    .el-dialog__footer {
      margin-top: 0;
      text-align: center;
      .el-button {
        padding: 0;
        margin-right: 20px;
        width: 80px;
        height: 36px;
      }
      .noBtn {
        border-color: #f3e7e1;
        background-color: #f3e7e1;
        color: #333;
      }
      .yesBtn {
        border-color: #ff5e20;
        background-color: #ff5e20;
      }
    }
  }
}
  .hzsDialog{
    // width: 300px;
    height: 200px;
    .el-icon-close{
      display: none;
    }
    .el-dialog__header{
      span{
        color: #000000;
      }
    .el-icon-warning{
      // background-color: #ff665f;
      margin-right: 10px;
    }
    }
    .el-button--primary{
      background-color:#7f9dff;
      margin-left: 0;
    }
  }
</style>
